package com.ali.memory;

/**
 * 
 * @author nathan
 * 
 *         注意使用-server模式。否则第二次Minor GC后，obj对象直接进Old区了<br>
 *         java -server -Xms40M -Xmx40M -Xmn16M -XX:SurvivorRatio=6 -verbose:gc
 *         -XX:+PrintGCDetails com/ali/memory/MinorGCDemo <br>
 *         jstat -gcutil [pid] 1000 100
 */
public class MinorGCDemo {
	public static void main(String[] args) throws InterruptedException {
		Thread.sleep(MemoObj.TIME_15_S);
		MemoObj obj = new MemoObj(MemoObj.SIZE_1_M);
		for (int i = 0; i < 2; ++i) {
			happenMinorGC();
		}
	}

	private static void happenMinorGC() throws InterruptedException {
		for (int i = 0; i < 11; ++i) {
			if (i == 10) {
				System.out.println("minor gc should happen");
			}
			new MemoObj(MemoObj.SIZE_1_M);
			Thread.sleep(MemoObj.TIME_1_S);
		}
	}
}
